package com.rmy.queue.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.rmy.common.core.domain.entity.SysDictData;
import com.rmy.common.utils.StringUtils;
import com.rmy.queue.service.IQmsWindowBusinessService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rmy.common.annotation.Log;
import com.rmy.common.core.controller.BaseController;
import com.rmy.common.core.domain.AjaxResult;
import com.rmy.common.enums.BusinessType;
import com.rmy.queue.domain.QmsBusinessConfig;
import com.rmy.queue.service.IQmsBusinessConfigService;
import com.rmy.common.utils.poi.ExcelUtil;
import com.rmy.common.core.page.TableDataInfo;

/**
 * 业务配置Controller
 * 
 * @author rmy
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/queue/businessconfig")
public class QmsBusinessConfigController extends BaseController
{
    @Autowired
    private IQmsBusinessConfigService qmsBusinessConfigService;

    @Autowired
    private IQmsWindowBusinessService qmsWindowBusinessService;

    /**
     * 查询业务配置列表
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(QmsBusinessConfig qmsBusinessConfig)
    {
        startPage();
        List<QmsBusinessConfig> list = qmsBusinessConfigService.selectQmsBusinessConfigList(qmsBusinessConfig);
        return getDataTable(list);
    }

    /**
     * 导出业务配置列表
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:export')")
    @Log(title = "业务配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QmsBusinessConfig qmsBusinessConfig)
    {
        List<QmsBusinessConfig> list = qmsBusinessConfigService.selectQmsBusinessConfigList(qmsBusinessConfig);
        ExcelUtil<QmsBusinessConfig> util = new ExcelUtil<QmsBusinessConfig>(QmsBusinessConfig.class);
        util.exportExcel(response, list, "业务配置数据");
    }

    /**
     * 获取业务配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qmsBusinessConfigService.selectQmsBusinessConfigById(id));
    }

    /**
     * 新增业务配置
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:add')")
    @Log(title = "业务配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QmsBusinessConfig qmsBusinessConfig)
    {
        return toAjax(qmsBusinessConfigService.insertQmsBusinessConfig(qmsBusinessConfig));
    }

    /**
     * 修改业务配置
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:edit')")
    @Log(title = "业务配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QmsBusinessConfig qmsBusinessConfig)
    {
        return toAjax(qmsBusinessConfigService.updateQmsBusinessConfig(qmsBusinessConfig));
    }

    /**
     * 删除业务配置
     */
    @PreAuthorize("@ss.hasPermi('queue:businessconfig:remove')")
    @Log(title = "业务配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        if ("1".equals(qmsWindowBusinessService.checkWindowBusinessConfigLink(ids))) {
            return AjaxResult.error("业务配置存在鹤位关联，不允许删除！");
        }
        return toAjax(qmsBusinessConfigService.deleteQmsBusinessConfigByIds(ids));
    }

}
